﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MegaMan
{
    class AnimatedGameEntity : GameEntity
    {

        private Rectangle sourceRectangle;
        public Rectangle SourceRectangle
        {
            get { return sourceRectangle; }
            set { sourceRectangle = value; }
        }

        private Animation currentAnimation;
        public Animation CurrentAnimation
        {
            get { return currentAnimation; }
            set { currentAnimation = value; }
        }

        private double frameTick;
        private int currentFrame = 0;

        public AnimatedGameEntity()
            : base()
        {

        }

        public override void Update(GameTime gameTime)
        {
            if (currentAnimation != null)
            {
                if (gameTime.TotalGameTime.TotalMilliseconds >= frameTick + currentAnimation.FrameTime)
                {
                    frameTick = gameTime.TotalGameTime.TotalMilliseconds;

                    currentFrame++;

                    if (currentFrame >= currentAnimation.FrameTotal)
                        currentFrame = 0;

                    sourceRectangle.X = (int)currentAnimation.FrameSize.X * currentFrame;
                    sourceRectangle.Y = 0;
                }
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
        }
    }
}